home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 November: Tool Chest / Dev.CD Nov 00 TC Disk 1.toast / Sample Code / Communications Toolbox / Get Tool Config / GetToolConfig.c next >
Encoding:
C/C++ Source or Header  |  2000-09-28  |  3.8 KB  |  128 lines  |  [TEXT/CWIE]

  1. /*
  2.     File:            GetToolConfig.c
  3.     
  4.     Description:    This q&d allows one to accumulate into a TEXT file the config strings 
  5.                 of Connection Tools that have been configured with CMChoose.
  6.  
  7.     Author:        GDG
  8.  
  9.     Copyright:     Copyright: © 1999 by Apple Computer, Inc.
  10.                 all rights reserved.
  11.     
  12.     Disclaimer:    You may incorporate this sample code into your applications without
  13.                 restriction, though the sample code has been provided "AS IS" and the
  14.                 responsibility for its operation is 100% yours.  However, what you are
  15.                 not permitted to do is to redistribute the source as "DSC Sample Code"
  16.                 after having made changes. If you're going to re-distribute the source,
  17.                 we require that you make it clear in the source that the code was
  18.                 descended from Apple Sample Code, but that you've made changes.
  19.     
  20.     Change History (most recent first):
  21.             6/22/99    Updated for Metrowerks Codewarrior Pro 2.1(KG)
  22.             2/97        recompiled PPC and 68K projects in CodeWarrior 11(MW)
  23.             8/30/91       fixed it up to be useful(GDG)
  24.             8/10/91    created this bugger from some existing source lying about(GDG)
  25.             
  26.  
  27. */
  28. #include <Traps.h>
  29. #include <stdio.h>
  30. #include <CommResources.h>
  31. #include <Connections.h>
  32. #include <Memory.h>
  33. #include <TextUtils.h>
  34. #include <CTBUtilities.h>
  35.  
  36. // function prototypes
  37. void main(void);
  38.  
  39. void main() {
  40.     short           procID;
  41.     ConnHandle      connection;
  42.     CMBufferSizes   bufSizes;
  43.     OSErr           err;
  44.     Str255          toolName;
  45.     Point           where;
  46.     short           result;
  47.     Ptr             configStream;
  48.     FILE*           fp;
  49.     
  50.     // putting something into TTY window initializes QD globals, etc.
  51.     printf("•• running Get Tool Config program ••\n\n");
  52.     
  53.     // initialize CTB and managers
  54.     if (NGetTrapAddress(_CommToolboxDispatch, OSTrap) ==
  55.         NGetTrapAddress(_Unimplemented, OSTrap)) {
  56.         printf("•• CTB Not available ••\n");
  57.         return;
  58.     }
  59.     if (noErr != InitCRM()) {
  60.         printf("•• CTB Available but InitCRM failed. ••\n");
  61.         return;
  62.     }
  63.     if (noErr != InitCTBUtilities()) {
  64.         printf("•• CTB Available: InitCTBUtilities Fail. ••\n");
  65.         return;
  66.     }
  67.     if (cmNoTools == InitCM()) {
  68.         printf("•• CTB Available: No connection tools found. ••\n");
  69.         return;
  70.     }
  71.     
  72.     // get a Connection Tool name
  73.     err = CRMGetIndToolName('cbnd',1,toolName);
  74.     if (err != noErr) {
  75.         printf("•• CRMGetIndToolName failed... no Conn Tool available ?!?!? ••\n");
  76.         return;
  77.     }
  78.     // get a resource ID for it
  79.     procID = CMGetProcID(toolName);
  80.     if (-1 == procID) {
  81.         printf("•• CMGetProcID: No 'Apple (ISDN) Serial Tool'. ••\n");
  82.         return;
  83.     }
  84.     
  85.     // init the CMBufferSizes variable so that Tool will init with defaults
  86.     bufSizes[cmDataIn] = 0;
  87.     bufSizes[cmDataOut] = 0;
  88.     bufSizes[cmCntlIn] = 0;
  89.     bufSizes[cmCntlOut] = 0;
  90.     bufSizes[cmAttnIn] = 0;
  91.     bufSizes[cmAttnOut] = 0;
  92.     
  93.     // now get a conn record set up 
  94.     connection = CMNew(procID, cmData|cmNoMenus|cmQuiet, bufSizes, 0, 0);
  95.     if (connection == nil) {
  96.         printf("•• CMNew: Can't create a CTB connection record. ••\n");
  97.         return;
  98.     }
  99.     
  100.     // CMChoose Dialog has to hang off this point (global coordinates)
  101.     SetPt(&where,20,40);
  102.     // now do CMChoose et al:
  103.     result = CMChoose(&connection,where,NULL);
  104.     if ((result == chooseOKMajor) || (result == chooseOKMinor)) {
  105.         configStream = CMGetConfig(connection);
  106.         if (configStream == NULL) {
  107.             printf("CMGetConfig failed\n\n");
  108.         } else {
  109.             CMGetToolName((**connection).procID,toolName);
  110.             p2cstr(toolName);
  111.             printf("• Configuration string for %s:\n'%s'\n\n",toolName, configStream);
  112.             fp = fopen("Tool Configs","a");
  113.             if (fp != NULL) {
  114.                 fprintf(fp,"• Configuration string for %s:\n'%s'\n\n",toolName, configStream);
  115.                 fclose(fp);
  116.                 printf("•• Configuration string info appended to file 'Tool Configs'. ••\n\n");
  117.             } else {
  118.                 printf("•• Output file could not be opened. ••\n");
  119.             }
  120.             DisposePtr(configStream);
  121.         }
  122.     } else {
  123.         printf("•• CMChoose failed. ••\n");
  124.     }
  125.     CMDispose(connection);
  126.     printf("•• closing Get Tool Config program ••\n\n");
  127. }
  128.